package com.xinyue.game.center.business.role;

import com.xinyue.game.center.business.account.AccountService;
import com.xinyue.game.center.business.role.param.CreateRoleRequest;
import com.xinyue.game.center.business.role.param.CreateRoleResponse;
import com.xinyue.game.center.common.AbstractGameCenterServerController;
import com.xinyue.game.center.common.ServerResponseEntity;
import com.xinyue.game.center.dao.entity.AccountEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("player")
public class PlayerController extends AbstractGameCenterServerController {

    @Autowired
    private PlayerService playerService;
    @Autowired
    private AccountService accountService;

    @PostMapping("createPlayer")
    public ServerResponseEntity createPlayer(@RequestBody CreateRoleRequest createRoleParam) throws Exception {
        AccountEntity accountEntity = accountService.getAndCheckAccount(createRoleParam.getUserId());
        CreateRoleResponse voCreateRole = playerService.createPlayer(accountEntity, createRoleParam);
        accountService.updateAccount(accountEntity);
        return responseSuccess(voCreateRole);
    }
}
